package topin.facecat.FaceCat.UI

import facecat.topin.btn.FCButton
import facecat.topin.core.FCColor
import facecat.topin.core.FCPaint
import facecat.topin.core.FCRect
import facecat.topin.div.FCDiv
import facecat.topin.scroll.FCScrollBar

/**
 * 滚动按钮
 */
class ScrollButtonM : FCButton() {
    /**
     * 重绘背景
     *
     * @param paint 绘图对象
     * @param clipRect 裁剪区域
     */
    override fun onPaintBackground(paint: FCPaint, clipRect: FCRect) {
        val parent = parent
        if (parent != null) {
            val scrollBar =
                (if (parent.parent is FCScrollBar) parent.parent else null) as FCScrollBar?
            var show = false
            if (scrollBar!!.addSpeed != 0) {
                show = true
            }
            val div =
                (if (scrollBar.parent is FCDiv) scrollBar.parent else null) as FCDiv?
            if (div!!.isDragScrolling) {
                show = true
            }
            if (show) {
                val cornerRadis = 8
                val width = width
                val height = height
                val drawRect = FCRect(0, 0, width, height)
                if (allowDrag() && this === m_native.pushedView) {
                    paint.fillRoundRect(FCColor.rgb(42, 138, 195), drawRect, cornerRadis)
                } else {
                    if (MyColor.m_style == 0) {
                        paint.fillRoundRect(FCColor.rgb(100, 100, 100), drawRect, cornerRadis)
                    } else {
                        paint.fillRoundRect(FCColor.rgb(200, 200, 200), drawRect, cornerRadis)
                    }
                }
            }
        }
    }

    /**
     * 创建透明按钮
     *
     */
    init {
        borderColor = FCColor.None
    }
}
